from django.utils import timezone

from django.db import models

# Create your models here.
STATUS_CHOICE = ((-1, "售完"), (0, "可借"))


class BookModel(models.Model):
    title = models.CharField(max_length=255, verbose_name="书籍名称")
    author = models.CharField(max_length=200, verbose_name="作者名称")
    serial_number = models.CharField(max_length=255, verbose_name="书籍编号", unique=True)
    publication_date = models.DateField(verbose_name="出版日期", null=True, blank=True)
    status = models.IntegerField(choices=STATUS_CHOICE, default=0, verbose_name="书籍状态", null=True, blank=True)
    stock = models.IntegerField(default=0, verbose_name="现货数量")
    created_date = models.DateTimeField(verbose_name="创建日期", auto_now_add=True)
    updated_date = models.DateTimeField(verbose_name="更新日期", auto_now=True)
    is_deleted = models.BooleanField(default=False)

    class Meta:
        db_table = "books"
        verbose_name = "书籍信息表"

    def __str__(self):
        return self.title


class BookBorrowRecordModel(models.Model):
    book = models.ForeignKey(BookModel, on_delete=models.CASCADE, verbose_name="书籍")
    borrower = models.CharField(max_length=200, verbose_name="借阅人")
    is_return = models.BooleanField(default=False, verbose_name="是否归还")
    number = models.IntegerField(default=0, verbose_name="借阅数量")
    borrow_date = models.DateTimeField(verbose_name="借阅日期", auto_now_add=True)
    return_date = models.DateTimeField(verbose_name="归还日期", null=True, blank=True)
    created_date = models.DateTimeField(verbose_name="创建日期", auto_now_add=True)
    updated_date = models.DateTimeField(verbose_name="更新日期", auto_now=True)
    is_deleted = models.BooleanField(default=False)

    class Meta:
        db_table = "book_borrow_record"
        verbose_name = "书籍借阅记录表"

    def __str__(self):
        return self.borrower
